package edu.pku.sei.mte.modelmatch;

import edu.pku.sei.mte.mtemodel.metamodel.RTypeGraph;
import edu.pku.sei.mte.mtemodel.model.MModelGraph;

public class ChocoMModelGraph {
	public MModelGraph model;
	public int nodeCount;
	public int edgeCount;
	
	public int[] nodeTypeArray;
	public int[] edgeTypeArray;
	public int[] edgeSourceArray;
	public int[] edgeTargetArray;
	public int[] edgeSourceOrderArray;
	public int[] edgeTargetOrderArray;
	
	public MMArrayEqual nodeTypeArrayEqual;
	public MMArrayEqual edgeTypeArrayEqual;
	public MMArrayEqual edgeSourceArrayEqual;
	public MMArrayEqual edgeTargetArrayEqual;
	public MMArrayEqual edgeSourceOrderArrayEqual;
	public MMArrayEqual edgeTargetOrderArrayEqual;
	
	public ChocoMModelGraph(MModelGraph model){
		this.model = model;
		nodeCount = model.getNodes().size();
		edgeCount = model.getEdges().size();
		
		nodeTypeArray = new int[nodeCount];
		edgeTypeArray = new int[edgeCount];
		edgeSourceArray = new int[edgeCount];
		edgeTargetArray = new int[edgeCount];
		edgeSourceOrderArray = new int[edgeCount];
		edgeTargetOrderArray = new int[edgeCount];
		
		nodeTypeArrayEqual = new MMArrayEqual(nodeTypeArray);
		edgeTypeArrayEqual = new MMArrayEqual(edgeTypeArray);
		edgeSourceArrayEqual = new MMArrayEqual(edgeSourceArray);
		edgeTargetArrayEqual = new MMArrayEqual(edgeTargetArray);
		edgeSourceOrderArrayEqual = new MMArrayEqual(edgeSourceOrderArray);
		edgeTargetOrderArrayEqual = new MMArrayEqual(edgeTargetOrderArray);
		
		RTypeGraph typeGraph = model.getTypeGraph();
		for(int i=0; i<nodeCount; i++){
			nodeTypeArray[i] = typeGraph.getNodes().indexOf(model.getNodes().get(i).getType()) + 1;
		}
		for(int i=0; i<edgeCount; i++){
			edgeTypeArray[i] = typeGraph.getEdges().indexOf(model.getEdges().get(i).getType()) + 1;
			edgeSourceArray[i] = model.getNodes().indexOf(model.getEdges().get(i).getSource());
			edgeTargetArray[i] = model.getNodes().indexOf(model.getEdges().get(i).getTarget());
			edgeSourceOrderArray[i] = model.getEdges().get(i).getSourceOrder();
			edgeTargetOrderArray[i] = model.getEdges().get(i).getTargetOrder();
		}
	}
}
